Post

Replies

Boosts

Views

Activity

NSURLErrorDomain Code=-1200
I am using the URLSession library to connect to certain pages using the https protocol. To get access to certain urls I had to create a delegate to include the public part of the certificate offered by the server. The problem I find is that in some urls the application does not call the method that I created in the delegate. What could be the problem? I include the snippet of the URLSession class and the delegated class that I created. let delegate: URLSessionDelegate = SessionDelegate() as URLSessionDelegate let urlSession = URLSession(configuration: .default, delegate: delegate, delegateQueue: nil) let task = urlSession.dataTask(with: request as URLRequest){ data, response, error in if error == nil { var htmlCode: String = "" if charset == Constantes.CHARSET_UTF8 { htmlCode = String(data: data!, encoding: .utf8)! } else { htmlCode = String(data: data!, encoding: .ascii)! } callback(htmlCode, nil) return } else { callback("", error.debugDescription) } } task.resume() And my delegate class: class SessionDelegate:NSObject, URLSessionDelegate { let certificadosName: [String] = ["AC_Administracion_Publica","ac_raiz_fnmt","Camerfirma_AAPP_II_Chambers_of_Commerce_Root","Camerfirma_Corporate_Server_II_Chambers_of_Commerce_Root","Chambers_of_Commerce_Root","claveRaiz","DigiCert_High_Assurance_EV_Root_CA","Entrust_Root_Certification_Authority_G","GeoTrust_SSL_CA_G_GeoTrust_Global_CA","Izenpe_com"] let certFileType = "cer" func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { guard challenge.previousFailureCount == 0 else { challenge.sender?.cancel(challenge) // Inform the user that the user name and password are incorrect completionHandler(.cancelAuthenticationChallenge, nil) return } if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust && challenge.protectionSpace.serverTrust != nil { let trust = challenge.protectionSpace.serverTrust var certs: [SecCertificate] = [SecCertificate]() for certificadoName in certificadosName { let pem = Bundle.main.url(forResource: certificadoName, withExtension: certFileType) let data = NSData(contentsOf: pem!) let cert = SecCertificateCreateWithData(nil, data!) certs.append(cert!) } SecTrustSetAnchorCertificates(trust!, certs as CFArray) var result=SecTrustResultType.invalid if SecTrustEvaluate(trust!,&result)==errSecSuccess { if result==SecTrustResultType.proceed || result==SecTrustResultType.unspecified { let proposedCredential = URLCredential(trust: trust!) completionHandler(.useCredential,proposedCredential) return } } } completionHandler(.performDefaultHandling, nil) } }
16
2
9.7k
Jan ’20
app crash on show UIDocumentMenuViewController from UIWebView
Hello, I am developing an app that allows access to different websites and shows the answer in a UIWebview. I have found that when trying to load a file from a web (html loaded in the UIWebview) using a file input, the app breaks in IOS13 and returns the following error:*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIDocumentMenuViewController (<UIDocumentMenuViewController: 0x7f7fbb021ea0>). In its current trait environment, the modalPresentationStyle of a UIDocumentMenuViewController with this style is UIModalPresentationPopover. You must provide location information for this popover through the view controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the view controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'I have been looking for solutions and I have found the solution that I show below to control the presentation of the UIDocumentMenuViewController should work, but it still gives the same error, since it does not enter the prepareForPopoverPresentation methodoverride open func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) { if #available(iOS 13, *), viewControllerToPresent is UIDocumentMenuViewController { viewControllerToPresent.popoverPresentationController?.delegate = self } super.present(viewControllerToPresent, animated: flag, completion: completion) } func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController) { popoverPresentationController.sourceView = self.view }What am I doing wrong so it doesn't work?
1
0
1.5k
Feb ’20
Error on integrate Firebase Analytics to my app
Hello, I am trying to integrate Firebase Analytics with my swift app and I have followed the instructions to do this integration on the official Firebase page and everything seems to work fine until I make use of the Analytics logEvent statement and it throws the following compile error: Undefined symbols for architecture x86_64: "_OBJCCLASS $ _ FIRApp", referenced from: objc-class-ref in AppDelegate.o "_OBJCCLASS $ _ FIRAnalytics", referenced from: objc-class-ref in FirebaseUtils.o
0
0
395
Apr ’21